import BaseView from '../baseView.js';

export default class AddCinema extends BaseView {
    render() {
        $('#Content').html(`
            <div>
                <h1>添加放映厅</h1>
                <hr/>
                </div>
                <div>
                <form class="layui-form" id='resetForm'>
                <div class="layui-form-item">
                <label class="layui-form-label">放映厅名：</label>
                    <div class="layui-input-block">
                    <input type="text" id="name" required   placeholder="请输入放映厅名称"  class="layui-input">
                    </div>
                </div>
                <form class="layui-form" action="">
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否营业：</label>
                        <div class="layui-input-block">
                            <select id="statuselect" name="状态" lay-verify="required">
                            <option value="0"></option>
                            <option value="是">是</option>
                            <option value="否">否</option>
                            </select>
                        </div>
                    </div>
                </form>

                <div class="layui-form-item">
                    <div class="layui-input-block">
                    <button type='button' id='addstudentBtn' class="layui-btn" lay-submit lay-filter="formDemo">添加</button>
                    <button type="reset" id='resetBtn' class="layui-btn layui-btn-primary">重置</button>
                    <button type="button" id='goToStudentListBtn' class="layui-btn layui-btn-warm">返回</button>
                    </div>
                </div>
                </form>
                </div>
            </div>

            <script>
            layui.use('form', function(){
            var form = layui.form;
            //获得表单
            myform = form
            //重新渲染表单
            form.render();
            });
            </script>
        `);
    }

    handle() {
        //绑定添加事件
        $("#addstudentBtn").click(() => {
            $.ajax({
                type: "post",
                url: "/theaters/addcinema",
                data: {
                    "name": $("#name").val(),
                    "status": $("#statuselect").val()
                },
                dataType: "json",
                success: (data) => {
                    //console.log(data)
                    if (data.code == 1) {
                        layer.msg(data.msg);
                        window.location.hash = "#/main/Showall";
                    } else {
                        layer.msg(data.msg);
                    }
                }
            })
        });

        //重置按钮
        $("#resetBtn").click(() => {
                // 清空表单数据
                $("#resetForm")[0].reset();
                // layui.form.render();
        })
        //返回
        $("#goToStudentListBtn").click(() => {
            window.location.hash = "#/main/Showall";
        })
    }
}

